# -*- coding: utf-8 -*-

import numpy as np

import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.axes import Axes

from mpl_matplotlib import mpl_font


# 单窗口多图表

def mpl_subplot():
    ncols = 2
    nrows = 2

    fig, axs = plt.subplots(ncols=ncols, nrows=nrows)
    x = np.linspace(start=-np.pi, stop=np.pi, num=201)
    axs[0, 0].set_title(label=f'第{1}副图')
    axs[1, 1].plot(x, np.cos(x))

    fig.show()

    pass


def figure_subplot():
    """Figure.add_subplot"""
    fig: Figure = plt.figure()
    ncols = 2
    nrows = 2
    for i in range(nrows * ncols):
        index = i + 1  # 不能写参数名，第三个参数从1开始
        ax: Axes = fig.add_subplot(nrows, ncols, index)
        ax.set_title(label=f'窗口{nrows}x{ncols}中第{index}副图')
        pass
    pass


def more_axes():
    """"""
    fig: Figure = plt.figure(figsize=(8, 6))
    fig.tight_layout()
    left = 0
    bottom = 0
    width = 1
    height = 1
    ax: Axes = fig.add_axes(rect=(left, bottom, width, height), frameon=False, facecolor='g')

    pass


if __name__ == '__main__':
    mpl_font()
    # mpl_subplot()
    # figure_subplot()

    # more_axes()

    plt.show()
    plt.close()

    pass
